﻿using System;
using System.Xml.Linq;

namespace Lightray.Hattrick.ChppLib.EntityTypes
{
    public class PlayerMatchStats
    {
        public DateTime MatchDate { get; private set; }
        public int MatchID { get; private set; }
        public int PlayedMinutes { get; private set; }
        public double Rating { get; private set; }
        public double RatingEndOfGame { get; private set; }

        protected PlayerMatchStats() { } 
        public static PlayerMatchStats FromXml(XElement xml)
        {
            if (xml == null || xml.IsEmpty)
                return null;

            HattrickXmlReader reader = new HattrickXmlReader(xml);
            return new PlayerMatchStats()
            {
                MatchDate = reader.ReadDate("Date"),
                MatchID = reader.ReadNumber("MatchId"),
                PlayedMinutes = reader.ReadNumber("PlayedMinutes"),
                Rating = reader.ReadFloatNumber("Rating"),
                RatingEndOfGame = reader.ReadFloatNumber("RatingEndOfGame"),
            };

            //TODO: what to do with position code            
        }

        public override string ToString()
        {
            return string.Format("{0}@{1}", MatchID, MatchDate);
        }
    }
}